﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Globalization;
using YQBlog.General;

namespace YQBlog.Controllers
{
    public class ThemesController : Controller
    {
        /// <summary>
        /// 更换当前页面风格（视图路径）
        /// </summary>
        public ActionResult ChangeTheme(string theme)
        {
            WebUtils.ChangeTheme(theme);
            string[] Keys = new[] { "/archive/", "/" + YQBlog.General.WebUtils.configinfo.WebStaticFolderPart1 + "/" };
            string key = Array.Find(Keys, element => Request.UrlReferrer.PathAndQuery.ToLower().IndexOf(element) > -1);
            if (!string.IsNullOrWhiteSpace(key))
            {
                string lang = Array.Find(WebUtils.Langs, element => Request.UrlReferrer.PathAndQuery.ToLower().IndexOf(element) > -1);
                if (!string.IsNullOrWhiteSpace(lang))
                {
                    return this.Redirect(lang);
                }
                return this.Redirect("/");
            }
            return this.Redirect(Request.UrlReferrer.ToString());
        }

    }
}
